package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.BrandBeanModel;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.BrandBeanView;
import com.squareup.okhttp.Request;

import java.util.Map;

/**
 * Created by Administrator on 2017/6/9.
 */

public class BrandBeanPresenter extends BasePresenter {

    private BrandBeanView brandBeanView;

    public BrandBeanPresenter(BrandBeanView brandBeanView) {
        this.brandBeanView = brandBeanView;
    }

    public void loadBrandData(final Context context) {
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String, String> params = getDefaultMD5Params("first", "brands");
        params.put("key", ConfigValue.DATA_KEY);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "first/brands", params,
                new BaseDelegate.ResultCallback<BrandBeanModel>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        dismiss();
                        Utils.showToast(context, ExceptionHelper.getMessage(e, context));
                    }

                    @Override
                    public void onResponse(BrandBeanModel response, Object tag) {
                        dismiss();
                        brandBeanView.brandBeanData(response);
                    }
                });
    }
}
